package com.swift.violent.mainstay.security.handler;

import com.swift.violent.mainstay.common.constants.ResultCode;
import com.swift.violent.mainstay.common.lang.CommonResultOutput;
import com.swift.violent.mainstay.security.exception.PreAuthorizeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 *
 * @author ruoyi
 */
@Slf4j
@RestControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class GlobalExceptionHandler {

    /**
     * 权限异常
     *
     * @return the object
     */
    @ExceptionHandler(PreAuthorizeException.class)
    public Object preAuthorizeException() {
        return CommonResultOutput.commonErrorOutput(ResultCode.UNAUTHORIZED.code, "没有权限，请联系管理员授权");
    }

}
